<script setup lang="ts">
/*
 * @description:
 * @fileName: AddEdit.vue
 * @params
 * @author: lxx
 * @date: 2025-07-08 20:56:56"
 * @version: V1.0.0
 */
import { dataSaveApi } from '@/api/system/dict'
import type { ItemFormInt } from '@/api/system/dict/types'
import { useAddEdit } from '@/hooks/system/useFramework'
import constants from '@/common/constant'

const dataFormRef = ref()

const formData = ref<ItemFormInt>({
  id: -1,
  dictName: '',
  dictCode: '',
  status: 1,
  memo: ''
})

const { loading, dialog, open, handleSubmitClick, handleCloseDialog } = useAddEdit<ItemFormInt>(dataSaveApi, formData, dataFormRef)

const rules = {
  dictName: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
  dictCode: [{ required: true, message: '请输入字典编码', trigger: 'blur' }]
}

defineExpose({
  open
})
</script>
<template>
  <!--字典弹窗-->
  <el-dialog v-loading="loading" v-model="dialog.visible" :title="dialog.title" width="500px" @close="handleCloseDialog">
    <el-form ref="dataFormRef" :model="formData" :rules="rules" label-width="80px">
      <el-form-item label="字典名称" prop="dictName">
        <el-input v-model="formData.dictName" placeholder="请输入字典名称" />
      </el-form-item>

      <el-form-item label="字典编码" prop="dictCode">
        <el-input v-model="formData.dictCode" placeholder="请输入字典编码" />
      </el-form-item>

      <el-form-item label="状态">
        <Dict :code="constants.STATUS" v-model="formData.status" type="radio" />
      </el-form-item>

      <el-form-item label="备注" prop="memo">
        <el-input v-model="formData.memo" type="textarea" placeholder="请输入备注" />
      </el-form-item>
    </el-form>

    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="handleSubmitClick()">确 定</el-button>
        <el-button @click="handleCloseDialog()">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<style lang="scss" scoped></style>
